package com.mengsenlin.service;

import com.mengsenlin.entity.Result;
import com.mengsenlin.entity.ShoppingCart;
import com.mengsenlin.entity.User;
import com.mengsenlin.mapper.CartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/8/18.
 */
@Service
public class CartService {
    @Autowired
    CartMapper cartMapper;

    public Result<ShoppingCart> addToCart(long goodsId, long speId, HttpSession session){
        Result<ShoppingCart> result;
        User user=(User)session.getAttribute("user");
        long userId = user.getId();
        int i = cartMapper.insertCart(userId, goodsId, speId);
        if(i < 1){
            result = new Result<ShoppingCart>(false, "加入购物车失败，请稍后重试!");
            return result;
        }

        result = new Result<ShoppingCart>(true);
        return result;
    }

}
